#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Tubemaster
#
# Copyright (C) 2009 Selim Ok <selimok@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# This is the simple installer of Tubemaster

import shutil 
import os
import sys

print 'Tubemaster Installer'


script_dir = os.path.join(os.getcwd(),os.path.dirname(sys.argv[0]))
install_dir = '/usr/share/tubemaster/'

print 'Creating directories ...'
if not os.path.exists(install_dir):
    try:
        os.mkdir(install_dir)
    except:
        print '*** An exception occured. Cannot create ' + install_dir + ' directory! Please check the access rights. ***'
        sys.exit(-1)


install_dirs = [
'src/',
'data/'
]

install_files = {
'bin/tubemaster':'/usr/bin/'
}


print 'Copying subdirectories ...'

for x in install_dirs:
    try:
        shutil.copytree(os.path.join(script_dir,x),os.path.join(install_dir,x))
    except:
        print '*** An exception occured. Cannot install ' + x + ' directory  ***'
        sys.exit(-1)

print 'Copying files ...'

try:
    for x in install_files:
        shutil.copy(os.path.join(script_dir,x),install_files[x])
except:
    print 'An exception occured. Please check the access rights.'
    sys.exit(-1)

print 'Installation successfully completed!'